import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/components/Login";
import Home from "@/components/Home";
import Order from "@/components/wokerSpace/Order";
import Equipment from "@/components/wokerSpace/Equipment";
import Finance from "@/components/wokerSpace/Finance";
import Match from "@/components/wokerSpace/Match";
import MyMessage from "@/components/wokerSpace/MyMessage";
import Notice from "@/components/wokerSpace/Notice";
import Space from "@/components/wokerSpace/Space";
import User from "@/components/wokerSpace/User";
import UserHome from "@/components/user/UserHome";
import UserOder from "@/components/user/UserOder";
import UserEq from "@/components/user/UserEq";
import MyRent from "../components/user/MyRent";
import UserNotice from "@/components/user/UserNotice";
import MyOrder from "@/components/user/MyOrder";

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: "/login", component: Login },
    { path: "/", redirect: "/login" },
    {
      path: "/home",
      component: Home,
      redirect: "/home/order",
      children: [
        {
          path: "/home/order", component: Order,
        },
        {
          path: "/home/user", component: User,
        },
        {
          path: "/home/equipment", component: Equipment,
        },
        {
          path: "/home/finance", component: Finance,
        },
        {
          path: "/home/match", component: Match,
        },
        {
          path: "/home/myMessage", component: MyMessage,
        },
        {
          path: "/home/notice", component: Notice,
        },
        {
          path: "/home/space", component: Space,
        },
      ]
    },
    {
      path: "/userHome",
      component: UserHome,
      children: [
        {
          path: "/userHome/order", component: UserOder
        },
        {
          path: "/userHome/eq", component: UserEq
        },
        {
          path: "/userHome/myRent", component: MyRent
        },
        {
          path: "/userHome/notice", component: UserNotice
        },
        {
          path: "/userHome/myOrder", component: MyOrder
        },
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path === "/login") return next();
  const token = window.sessionStorage.getItem("token");
  if (!token) {
    alert("请登录");
    // this.$message.warning(请登录);
    return next("/login");
  }
  next();
})

export default router
